package com.androidy;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;


public class full_image extends Activity implements OnClickListener {
	Bitmap result = null;
	ImageView image = null;
	String img = "";
	String title = "";
	Button back = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.full_image);
		        
		Bundle extras = getIntent().getExtras();
	    if (extras != null) {
	    	img = extras.getString("img");
	    	title = extras.getString("title");
	    }
		image = (ImageView)this.findViewById(R.id.full_image);
		
		back = (Button)this.findViewById(R.id.back);
		back.setOnClickListener(this);
		back.setText("back");
		
		LinearLayout head_layout = (LinearLayout)this.findViewById(R.id.natvigation);
		head_layout.setBackgroundResource(R.drawable.blue);
		
		new UpdateList().execute();
    }
    
	public void show_img(){
		if (result != null){
			image.setImageBitmap(result);
			Toast.makeText(this, title, Toast.LENGTH_LONG).show();
		}
	}
	
	public class UpdateList extends AsyncTask<Void, Void, Void> {
		ProgressDialog progressDialog = null;
		
		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			progressDialog = common.generate_loading_message(full_image.this);
		}

		@Override
		protected Void doInBackground(Void... arg0) {
			result= dbConnection.getBitmapFromURL(img);
			return null;
		}
		
		@Override
		protected void onPostExecute(Void result) {
			// TODO Auto-generated method stub
			show_img();
			if (progressDialog != null)
				progressDialog.dismiss();
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		full_image.this.finish();
	}
	
}
